package com.cierzo.eagleband.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;

import javax.xml.xpath.*;

import org.xml.sax.InputSource;



public class ReadPacket {

	
	/**
	 * @param args
	 * @throws XPathExpressionException 
	 * @throws FileNotFoundException 
	 * @throws UnsupportedEncodingException 
	 */
	public static void main(String[] args) throws XPathExpressionException, FileNotFoundException, UnsupportedEncodingException {
		
		XPathFactory  factory=XPathFactory.newInstance();
		XPath xPath=factory.newXPath();
		
		String xmlDocument =  "<article level=\"Advanced\" date=\"October-2003\">" +
				"<title>Advance DAO Programming</title>" +
				"<author>Sean Sullivan </author></article>";
		
		XPathExpression  xPathExpression= xPath.compile("/article/title");
		InputSource inputSource = new InputSource(new StringReader(xmlDocument)); 
		
		String title =  xPathExpression.evaluate(inputSource);
		System.out.println(title);
	}
	
	
	public String getValor(String packet,String expresion) throws XPathExpressionException{
		String valor = "";
		XPathFactory  factory=XPathFactory.newInstance();
		XPath xPath=factory.newXPath();				
		XPathExpression  xPathExpression= xPath.compile(expresion);
		InputSource inputSource = new InputSource(new StringReader(packet)); 		
		valor =  xPathExpression.evaluate(inputSource);	
		return valor;
	}
	
}
